package com.tc.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtil {
	/**将日期转换成字符串
	 * 
	 * @param date
	 * @return
	 */
	public static String date2Str(Date date){
		SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return format.format(date);
	}

    /**将字符串转换为日期
     *
     * @param str
     * @return
     */
	public static Date str2Date(String str){
        SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date= null;
        try {
            date = format.parse(str);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }
    public static void main(String[] args) {
        try{
        //System.out.println(date2Str(new Date()));
            System.out.println(date2Str(str2Date("2018-10-24 15:38:30")));
            System.out.println(date2Str(new Date()));
        }catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }
	}
}
